1 module firecracker_d.models.mmds;
2 public import std.json;
3 // std.json is exported for ease of use
4 import firecracker_d.models.base_model;
5 
6 /***
7 * MicroVM Data Store
8 * Note: requires `allow_mmds_requests == true` on the network interface to access.
9 ***/
10 struct MMDS {
11 	/*
12 	* There's no good way to handle this, so 
13 	* we just expose the JSON object to the user.
14 	*/
15 	   
16 	JSONValue content;
17 
18 	/***
19     * Create a new MMDS via the Firecracker API. 
20 	* Throws: FirecrackerException on error.
21 	***/
22 	bool put(FirecrackerAPIClient cl) {
23 		Response r = cl.put("/mmds", content.toString);
24 		if(r.code == 204) {
25 			return true;
26 		}
27 		else {
28 			throwFromResponse(r);
29 			return false;
30 		}
31 	}
32 
33 
34 	/***
35 	* Update the content of the MMDS via the Firecracker API. 
36 	* Throws: FirecrackerException on error.
37 	***/
38 	bool patch(FirecrackerAPIClient cl) {
39 		Response r = cl.patch("/mmds", content.toString);
40 		if(r.code == 204) {
41 			return true;
42 		}
43 		else {
44 			throwFromResponse(r);
45 			return false;
46 		}
47 	}
48 
49 
50 	/***
51 	* Get the MMDS via the Firecracker API. 
52 	* Throws: FirecrackerException on error.
53 	***/
54 	this(FirecrackerAPIClient cl) {
55 		Response r = cl.get("/mmds");
56 		if(r.code == 200) {
57 			content = r.responseBody.toString.parseJSON;
58 		}
59 		else {
60 			throwFromResponse(r);
61 		}
62 	}
63 }
64 
65 /***
66 * Defines the MMDS configuration.
67 ***/
68 struct MMDSConfig {
69     mixin BaseModel;
70 
71     /***
72     * IPv4 address that the MMDS is reachable through (on the VM side)
73     ***/
74     @serializationKeys("ipv4_address") string ipv4Address;
75 
76 	/***
77     * Apply MMDS config via the Firecracker API (prior to boot).  
78 	* Throws: FirecrackerException on error.
79 	***/
80 	bool put(FirecrackerAPIClient cl) {
81 		Response r = cl.put("/mmds/config", this.stringify);
82 		if(r.code == 204) {
83 			return true;
84 		}
85 		else {
86 			throwFromResponse(r);
87 			return false;
88 		}
89 	}
90 }
91 
92    
93     
94